<%@ page import="javax.xml.ws.Response" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <jsp:include page="../inc.jsp"></jsp:include>
</head>
<body class="easyui-layout" id="category_layout">
<div data-options="region:'west',title:'',split:true" style="width:200px;">
    <a id="add_categrory" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'">新增</a>
    <ul id="category_tree"></ul>
</div>
<div data-options="region:'center',title:''" style="padding:5px;">

</div>
<div id="category_Menubtns" style="width: 120px; display: none;">
    <div title="update" data-options="iconCls:'icon-edit'">修改</div>
    <div title="delete" data-options="iconCls:'icon-no'">删除</div>
</div>

<script>
    var categrory_center_panle;
    var categrory_Menubtns;
    $(function(){
        categrory_Menubtns = $('#category_Menubtns').menu({
            onClick : function(item) {
                var curTabTitle = $(this).data('categroy_tree_node');
                var menuId = curTabTitle.categoryId;
                var type = $(item.target).attr('title');
                if(type==="update"){
                    categrory_center_panle.panel('open').panel('refresh','${pageContext.request.contextPath}/category/update/'+menuId);
                }
                if(type==="delete"){
                    $.ajax({
                        type: "DELETE",
                        url: "${pageContext.request.contextPath}/category/delete/"+menuId,
                        success: function(data){
                            $('#category_tree').tree("reload");
                        },
                        error:function(XMLHttpRequest, textStatus, errorThrown){
                            console.info(XMLHttpRequest);
                            console.info(textStatus);
                            console.info(errorThrown);
                        }
                    });
                }
            }
        });
        categrory_center_panle = $('#category_layout').layout('panel','center');
        var category_url  =  "${pageContext.request.contextPath}/category/all";//分类菜单URL
        $('#category_tree').tree({
            url : category_url,
            method:'post',
            onClick : function(node) {
                console.info(node);
                categrory_center_panle.panel('open').panel('refresh','${pageContext.request.contextPath}/category/update/'+node.categoryId);
            },
            onContextMenu : function(e, node) {
                e.preventDefault();
                categrory_Menubtns.menu('show', {
                    left : e.pageX,
                    top : e.pageY
                }).data('categroy_tree_node', node);
            },
            loadFilter:function(data,parent){
                var data  = data.data;
                console.info(data);
                return data;
            }
        });
        $("#add_categrory").click(function(){
            categrory_center_panle.panel('open').panel('refresh','${pageContext.request.contextPath}/category/add');
        });
    });
</script>
</body>
</html>
